package system.activity;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Collection;

import javax.swing.JPanel;

import net.ericaro.surfaceplotter.JSurfacePanel;

import org.math.plot.PlotPanel;

import system.view.MainWindowImpl;
import user.view.Controls;

public class MainWindowActivity implements MainListener{

	MainWindowImpl mainWindow = new MainWindowImpl();
	String statusText;
	public MainWindowActivity() {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				mainWindow.setVisible(true);
				init();
			}
		});
	}
	@Override
	public void needRepaint() {
		mainWindow.repaint();
		mainWindow.show();
	}
	@Override
	public void addPanel(JPanel panel) 
	{
		mainWindow.addPanel(panel);
	}
	void init()
	{
		mainWindow.setListener(this);
	}
	@Override
	public void addPanel(Controls panel) 
	{
		mainWindow.clearCenterPanel();
		mainWindow.addLeftPanel(panel);
	}
	@Override
	public void addImagePanel(BufferedImage image, String name) 
	{
		mainWindow.updateImagePanel(image, name);
	}
	@Override
	public void addImagePanel(File imageFile) throws IOException 
	{
		mainWindow.updateImagePanel(imageFile);
	}
	@Override
	public void addRightPanel(JPanel panel)
	{
		mainWindow.addRightPanel(panel);
	}
	@Override
	public void clearImagePanel()
	{
		mainWindow.clearCenterPanel();
	}
	@Override
	public void removeLeftPanel()
	{
		mainWindow.clearLeftPanel();
	}
	@Override
	public Collection<String> getControlDescription()
	{
		return mainWindow.getControlDescription();
	}
	@Override
	public Collection<BufferedImage> getImages()
	{
		return mainWindow.getImages();
	}
	@Override
	public void removeRihtPanel()
	{
		mainWindow.clearRightPanel();
		
	}
	@Override
	public void setStatus(String statusText)
	{
		mainWindow.setStatusText(statusText);
	}
	@Override
	public void setLoadStatus()
	{
		System.out.println("Set cursor");
		statusText = mainWindow.getStatusText();
		mainWindow.setStatusText("Статус: вычисляю");
	//	mainWindow.getTimer().start();
		//mainWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	}
	@Override
	public void removeLoadStatus()
	{
		System.out.println("Remove cursor");
		//mainWindow.getTimer().stop();
		mainWindow.setStatusText(statusText);
		//mainWindow.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}
	@Override
	public String getControlHistoryDescription()
	{
		return mainWindow.getControlHistoryDescription();
	}
	@Override
	public void clearAll()
	{
		mainWindow.clearCenterPanel();
		mainWindow.clearLeftPanel();
		mainWindow.clearRightPanel();
	}
	@Override
	public void showErrorMessage(String message) {
		mainWindow.showErrorMessage(message);
	}
	@Override
	public void addPlotPanel(PlotPanel plot, String name) {
		mainWindow.updateImagePanel(plot, name);
	}
	@Override
	public void addFastPlotPanel(JSurfacePanel jSurfacePanel, String name) {
		System.out.println("addFastPlotPanel");
		mainWindow.updateImagePanel(jSurfacePanel, name);
		
	}
}
